<?php

use think\Db;
use think\migration\Seeder;

class SystemInit extends Seeder
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run()
    {
        $roleData = $this->getSystemAdminRoleData();
        Db::name('system_role')->insert($roleData);

        $admin = $this->getSystemAdminData();
        Db::name('system_user')->insert($admin);

        $userRoleRelation = [
          'user_id' => 1,
          'role_id' => 1
        ];
        Db::name('system_user_role')->insert($userRoleRelation);

        $menu = $this->getSystemMenuData();
        Db::name('system_menu')->insertAll($menu);

        $module = $this->getSystemModuleData();
        Db::name('system_module')->insert($module);

    }

    /**
     * 获取系统管理员角色数据
     */
    protected function getSystemModuleData()
    {
        $time = time();
        return [
            'name' => 'system',
            'title' => '系统管理',
            'intro' => '用户管理、用户权限、系统基本配置',
            'create_time' => $time,
            'update_time' => $time
        ];
    }
    
    /**
     * 获取系统管理员角色数据
     */
    protected function getSystemAdminRoleData()
    {
        $time = time();
        return [
            'name' => '超级管理员',
            'intro' => '拥有至高无上的权限',
            'auth' => '',
            'create_time' => $time,
            'update_time' => $time
        ];
    }

    /**
     * 获取系统管理员数据
     */
    protected function getSystemAdminData()
    {
        $time = time();
        return [
            'username' => 'admin',
            'nickname' => '超级管理员',
            'password' => password_hash('654321',PASSWORD_DEFAULT),
            'status' => 1,
            'headimgurl' => '',
            'gender' => 1,
            'phone' => '18682395282',
            'create_time' => $time,
            'update_time' => $time
        ];
    }

    /**
     * 获取系统菜单数据
     */
    protected function getSystemMenuData()
    {
        return array (
            0 => 
            array (
              'id' => '1',
              'pid' => '0',
              'module' => 'system',
              'user_id' => '1',
              'title' => '系统管理',
              'href' => 'system.index/index',
              'icon' => 'layui-icon-set',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '0',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            1 => 
            array (
              'id' => '2',
              'pid' => '1',
              'module' => 'system',
              'user_id' => '1',
              'title' => '用户管理',
              'href' => 'system.user/index',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '1',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            2 => 
            array (
              'id' => '3',
              'pid' => '1',
              'module' => 'system',
              'user_id' => '1',
              'title' => '角色管理',
              'href' => 'system.role/index',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '1',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            3 => 
            array (
              'id' => '4',
              'pid' => '1',
              'module' => 'system',
              'user_id' => '1',
              'title' => '权限管理',
              'href' => 'system.menu/index',
              'icon' => 'layui-icon-list',
              'sort' => '9',
              'status' => '1',
              'is_sys' => '0',
              'type' => '1',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            4 => 
            array (
              'id' => '5',
              'pid' => '2',
              'module' => 'system',
              'user_id' => '1',
              'title' => '管理员删除',
              'href' => 'system.user/del',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            5 => 
            array (
              'id' => '6',
              'pid' => '2',
              'module' => 'system',
              'user_id' => '1',
              'title' => '管理员增加',
              'href' => 'system.user/add',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            6 => 
            array (
              'id' => '7',
              'pid' => '2',
              'module' => 'system',
              'user_id' => '1',
              'title' => '管理员编辑',
              'href' => 'system.user/edit',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            7 => 
            array (
              'id' => '8',
              'pid' => '3',
              'module' => 'system',
              'user_id' => '1',
              'title' => '角色修改',
              'href' => 'system.role/edit',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            8 => 
            array (
              'id' => '9',
              'pid' => '3',
              'module' => 'system',
              'user_id' => '1',
              'title' => '角色删除',
              'href' => 'system.role/del',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            9 => 
            array (
              'id' => '10',
              'pid' => '3',
              'module' => 'system',
              'user_id' => '1',
              'title' => '角色增加',
              'href' => 'system.role/add',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            10 => 
            array (
              'id' => '11',
              'pid' => '3',
              'module' => 'system',
              'user_id' => '1',
              'title' => '角色的权限分配',
              'href' => 'system.role/menu',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            11 => 
            array (
              'id' => '12',
              'pid' => '4',
              'module' => 'system',
              'user_id' => '1',
              'title' => '增加权限 ',
              'href' => 'system.menu/add',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            12 => 
            array (
              'id' => '13',
              'pid' => '4',
              'module' => 'system',
              'user_id' => '1',
              'title' => '修改权限',
              'href' => 'system.menu/edit',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            13 => 
            array (
              'id' => '14',
              'pid' => '4',
              'module' => 'system',
              'user_id' => '1',
              'title' => '删除权限',
              'href' => 'system.menu/del',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            14 => 
            array (
              'id' => '15',
              'pid' => '3',
              'module' => 'system',
              'user_id' => '1',
              'title' => '批量删除',
              'href' => 'system.menu/del_all',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
			15 => 
            array (
              'id' => '16',
              'pid' => '3',
              'module' => 'system',
              'user_id' => '1',
              'title' => '菜单状态',
              'href' => 'system.menu/status',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '2',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
            16 => 
            array (
              'id' => '17',
              'pid' => '1',
              'module' => 'system',
              'user_id' => '1',
              'title' => '系统设置',
              'href' => 'system.config/index',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '1',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            ),
			17 => 
            array (
              'id' => '18',
              'pid' => '1',
              'module' => 'system',
              'user_id' => '1',
              'title' => '控制台',
              'href' => 'system.index/console',
              'icon' => '',
              'sort' => '10',
              'status' => '1',
              'is_sys' => '0',
              'type' => '1',
              'create_time' => time(),
              'update_time' => '0',
              'delete_time' => null,
            )
        );
    }
}